/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-06-25 23:01:42
 * @LastEditors: paddies
 * @LastEditTime: 2025-08-12 01:00:35
 * @FilePath: /shared_components/lib/luntai-components/build-show-pay-info/buildShowPayInfo.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-button/buildButton.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-image/buildImage.dart';
import 'package:shared_components/build-input-password/buildInputPassword.dart';
import 'package:shared_components/build-radio-group/buildRadioGroup.dart';
import 'package:shared_components/luntai-components/build-show-pay-info/buildChoosePayType.dart';

buildShowPayInfo(
    {dynamic res, Function? okCallBack, Function? passwordOkCallBack}) {
  var price = showText(res["price"]);
  var totalPrice = showText(res["totalPrice"]);
  var couponPrice = showText(res['couponPrice']);
  var pointPrice = showText(res['pointPrice']);
  var feeDetails = [];
  var payType = "YE".obs;
  if (res["feeDetails"] != null) {
    feeDetails = res["feeDetails"];
  }
  var screenBottomHeight = MediaQuery.of(Get.overlayContext!).padding.bottom;
  print("内容======");
  print(res);
  Get.bottomSheet(
      isScrollControlled: true,
      Container(
        padding: EdgeInsets.only(left: 10, right: 10, top: 20),
        decoration: new BoxDecoration(
          color: Colors.white,
          // new Radius.circular(20.0)
          borderRadius: new BorderRadius.only(
              topLeft: new Radius.circular(20.0),
              topRight: new Radius.circular(20.0)), //圆角
        ),
        height: 600,
        child: Obx(() => Container(
            width: double.infinity,
            height: double.infinity,
            // color: Colors.red,
            child: Column(children: [
              Container(
                width: double.infinity,
                alignment: Alignment.center,
                padding: EdgeInsets.only(bottom: 20),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "费用明细",
                      style:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                    ),
                    GestureDetector(
                        onTap: () {
                          Get.back();
                        },
                        child: Text(
                          "取消",
                          style: TextStyle(color: Color(0xff999999)),
                        ))
                  ],
                ),
              ),
              Expanded(
                  child: Container(
                      width: double.infinity,
                      height: double.infinity,
                      // color: Colors.yellow,
                      child: SingleChildScrollView(
                          child: Column(
                        children: [
                          ...feeDetails.map((e) {
                            return Container(
                              width: double.infinity,
                              margin: EdgeInsets.only(top: 2, bottom: 2),
                              // height: 50,
                              // color: Colors.red,
                              child: Column(
                                children: [
                                  Visibility(
                                      visible: e["type"] == 'new' &&
                                          showText(e["url"]) != "",
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Container(
                                            width: 80,
                                            height: 80,
                                            // color: Colors.red,
                                            child: buildImage(
                                                type: "ClipRect",
                                                url: showText(e["url"]),
                                                radius: 5),
                                          ),
                                          Expanded(
                                              child: Container(
                                            width: double.infinity,
                                            height: 80,
                                            padding: EdgeInsets.only(
                                                left: 15, right: 15),
                                            child: Column(
                                              children: [
                                                Expanded(
                                                    child: Container(
                                                  width: double.infinity,
                                                  height: double.infinity,
                                                  // color: Colors.yellow,
                                                  child: Text(
                                                      showText(e["name"]),
                                                      maxLines: 2,
                                                      style: TextStyle(
                                                          overflow: TextOverflow
                                                              .ellipsis,
                                                          fontSize: 16,
                                                          fontWeight:
                                                              FontWeight.bold)),
                                                )),
                                                Container(
                                                  width: double.infinity,
                                                  height: 30,
                                                  // color: Colors.green,
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                    children: [
                                                      Text(
                                                          "x" +
                                                              showText(
                                                                  e["num"]),
                                                          style: TextStyle(
                                                              color: Color(
                                                                  0xff888888))),
                                                      Row(
                                                        children: [
                                                          Text(
                                                            "价格 ",
                                                            style: TextStyle(
                                                                fontSize: 12,
                                                                color: Color(
                                                                    0xff888888)),
                                                          ),
                                                          Text(
                                                            "¥",
                                                            style: TextStyle(
                                                                fontSize: 11),
                                                          ),
                                                          Text(
                                                            showText(
                                                                e['total']),
                                                            style: TextStyle(
                                                                fontSize: 15,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          )
                                                        ],
                                                      )
                                                    ],
                                                  ),
                                                )
                                              ],
                                            ),
                                          ))
                                          // Expanded(
                                          //     child: Text(
                                          //   showText(e["name"]),
                                          //   overflow: TextOverflow.ellipsis,
                                          //   maxLines: 1,
                                          // )),
                                          // Expanded(
                                          //   child: Row(
                                          //     mainAxisAlignment:
                                          //         MainAxisAlignment
                                          //             .spaceBetween,
                                          //     children: [
                                          //       Expanded(
                                          //           child: Container(
                                          //         child: Text("¥" +
                                          //             showText(e["value"]) +
                                          //             " x " +
                                          //             showText(e["num"])),
                                          //       )),
                                          //       Text(
                                          //         "¥" + showText(e["total"]),
                                          //         style: TextStyle(
                                          //             color: Colors.red,
                                          //             fontWeight:
                                          //                 FontWeight.bold),
                                          //       ),
                                          //     ],
                                          //   ),
                                          // )
                                        ],
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'new' &&
                                          showText(e["url"]) == "",
                                      child: Padding(
                                        padding:
                                            EdgeInsets.only(top: 5, bottom: 5),
                                        child: Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Expanded(
                                              child: Text(
                                                showText(e["name"]),
                                                style: TextStyle(
                                                    fontWeight: FontWeight.bold,
                                                    fontSize: 16),
                                              ),
                                            ),
                                            Expanded(
                                                child: Container(
                                              alignment: Alignment.centerRight,
                                              width: double.infinity,
                                              child: Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment.end,
                                                children: [
                                                  Text("¥"),
                                                  Text(
                                                    showText(e["total"]),
                                                    style: TextStyle(
                                                        fontWeight:
                                                            FontWeight.bold,
                                                        fontSize: 16),
                                                  )
                                                ],
                                              ),
                                            ))
                                          ],
                                        ),
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'reward',
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.end,
                                        children: [
                                          Text(
                                            showText(e["name"]) +
                                                "：¥" +
                                                showText(e["value"]),
                                            style: TextStyle(color: Colors.red),
                                          )
                                        ],
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'new_extend',
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(showText(e["name"])),
                                          Row(
                                            children: [
                                              Text(
                                                "¥" + showText(e["value"]),
                                                style: TextStyle(
                                                    fontSize: 16,
                                                    fontWeight: FontWeight.bold,
                                                    color: Colors.red),
                                              ),
                                              Visibility(
                                                  visible:
                                                      showText(e["num"]) != "0",
                                                  child: Text(" x " +
                                                      showText(e["num"])))
                                            ],
                                          ),
                                          // Text(showText(e["total"])),
                                        ],
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'product',
                                      child: Container(
                                        width: double.infinity,
                                        height: 60,
                                        // color: Colors.blue,
                                        child: Row(
                                          children: [
                                            Container(
                                              width: 60,
                                              height: double.infinity,
                                              // color: Colors.green,
                                              child: buildImage(
                                                  type: "ClipRect",
                                                  url: showText(e["url"])),
                                            ),
                                            Expanded(
                                                child: Container(
                                              width: double.infinity,
                                              height: double.infinity,
                                              // color: Colors.teal,
                                              padding: EdgeInsets.only(
                                                  left: 10, right: 10),
                                              child: Column(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Row(
                                                    children: [
                                                      Text(showText(e["name"]))
                                                    ],
                                                  ),
                                                  Expanded(
                                                      child: Row(
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment.end,
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                    children: [
                                                      Text(
                                                          "¥" +
                                                              showText(
                                                                  e["value"]),
                                                          style: TextStyle(
                                                              fontSize: 16,
                                                              fontWeight:
                                                                  FontWeight
                                                                      .bold,
                                                              color:
                                                                  Colors.red)),
                                                      Text("x" +
                                                          showText(e["num"]))
                                                    ],
                                                  ))
                                                ],
                                              ),
                                            ))
                                          ],
                                        ),
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'fee',
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(showText(e["name"])),
                                          Row(
                                            children: [
                                              Text(
                                                "¥" + showText(e["value"]),
                                                style: TextStyle(
                                                    fontSize: 16,
                                                    fontWeight: FontWeight.bold,
                                                    color: Colors.red),
                                              ),
                                              Visibility(
                                                  visible:
                                                      showText(e["num"]) != "0",
                                                  child: Text(" x " +
                                                      showText(e["num"])))
                                            ],
                                          )
                                        ],
                                      )),
                                  Visibility(
                                      visible: e["type"] == 'other',
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(showText(e["name"])),
                                          Row(
                                            children: [
                                              Text(showText(e["value"])),
                                            ],
                                          )
                                        ],
                                      ))
                                ],
                              ),
                            );
                          }).toList(),
                          SizedBox(
                            height: 15,
                          ),
                          Container(
                            width: double.infinity,
                            child: Text(
                              "请选择支付方式",
                              style: TextStyle(
                                  fontSize: 16, fontWeight: FontWeight.bold),
                            ),
                          ),
                          buildNewRadioGrou(
                              list: [
                                // {"label": "积分支付", "value": "JF"},
                                {"label": "余额支付", "icon": "yue", "value": "YE"},
                                {
                                  "label": "支付宝",
                                  "icon": "zhifubao",
                                  "value": "ALI"
                                },
                                {
                                  "label": "微信支付",
                                  "value": "WX",
                                  "icon": "weixin",
                                }
                              ],
                              widthFactor: 3,
                              activeValue: payType.value,
                              onChange: (value) {
                                print("99999");
                                payType.value = value;
                                // onChangePayType(value)
                                // payType.value = value;
                                // if (onChange !=
                                //     null) {
                                //   onChange(value);
                                // }
                              }),
                          // Container(
                          //   padding: EdgeInsets.only(top: 20),
                          //   width: double.infinity,
                          //   alignment: Alignment.centerRight,
                          //   child: Text("应付合计：¥" + showText(totalPrice),
                          //       style: TextStyle(
                          //         color: Colors.red,
                          //         fontWeight: FontWeight.bold,
                          //       )),
                          // )
                        ],
                      )))),
              Container(
                width: double.infinity,
                height: 80,
                // color: Colors.blue,
                padding:
                    EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Container(
                      width: 200,
                      height: double.infinity,
                      // color: Colors.green,
                      alignment: Alignment.centerLeft,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Visibility(
                              visible: showText(couponPrice) != '0' &&
                                  showText(couponPrice) != '',
                              child: Row(
                                children: [
                                  Text("优惠券："),
                                  Text("¥" + showText(couponPrice),
                                      style: TextStyle(
                                        color: Colors.red,
                                        fontWeight: FontWeight.bold,
                                      )),
                                ],
                              )),
                          Visibility(
                              visible: showText(pointPrice) != "0" &&
                                  showText(pointPrice) != '',
                              child: Row(
                                children: [
                                  Text("积分抵扣："),
                                  Text("¥" + showText(pointPrice),
                                      style: TextStyle(
                                        color: Colors.red,
                                        fontWeight: FontWeight.bold,
                                      )),
                                ],
                              )),
                          Row(
                            children: [
                              Text("应付："),
                              Text("￥" + price,
                                  style: TextStyle(
                                    // color: Colors.red,
                                    fontWeight: FontWeight.bold,
                                  )),
                            ],
                          )

                          // Text(
                          //   "￥" + price,
                          //   style: TextStyle(
                          //     fontSize: 18,
                          //     color: Colors.red,
                          //     fontWeight: FontWeight.bold,
                          //   ),
                          // )
                        ],
                      ),
                    ),
                    Expanded(
                        child: Container(
                            padding: EdgeInsets.only(top: 5, bottom: 5),
                            child: buildButton(
                                title: "立即支付",
                                onClick: () {
                                  //如果是余额支付，需要输密码
                                  if (payType.value == "YE") {
                                    // 校验支付密码
                                    buildInputPassword(
                                        payType: "余额支付",
                                        price: price,
                                        onSuccess: (value) async {
                                          print("输入的密码是===");
                                          print(value);
                                          if (passwordOkCallBack != null) {
                                            passwordOkCallBack(
                                                payType.value, value);
                                          }

                                          // var map = {
                                          //   "ll-play": "YE",
                                          //   "jf-play": "HYJF"
                                          // };
                                          // doInnerPay(
                                          //         orderNo: serialNo.value,
                                          //         payType: map[method] ?? "",
                                          //         productType: payModule,
                                          //         payPassword: value ?? "")
                                          //     .then((res1) {
                                          //   // Get.back();
                                          //   // Fluttertoast.showToast(msg: "支付完成");
                                          //   print("这里支付完成");
                                          //   resolve(true);
                                          //   // paySuccessTip();
                                          // });
                                        });

                                    return;
                                  }
                                  if (okCallBack != null) {
                                    //弹窗选择支付方式
                                    okCallBack(payType.value);
                                    // buildChoosePayType(
                                    //     payType: payType.value,
                                    //     okCallBack: (value) {
                                    //       payType.value = value;
                                    //       okCallBack(payType.value);
                                    //     });
                                  }
                                  // Get.back();
                                },
                                colors: [
                                  Color(0xffF9110D),
                                  Color(0xffF9110D)
                                ])))
                  ],
                ),
              ),
              Container(
                width: double.infinity,
                height: screenBottomHeight,
              )
            ]))),
      ));
}

// buildChoosePayType({String payType = '', Function? okCallBack}) {
//   var myPayType = "".obs;
//   myPayType.value = payType;
//   Get.bottomSheet(
//       isScrollControlled: true,
//       Container(
//           padding: EdgeInsets.only(left: 10, right: 10, top: 20),
//           decoration: new BoxDecoration(
//             color: Colors.white,
//             // new Radius.circular(20.0)
//             borderRadius: new BorderRadius.only(
//                 topLeft: new Radius.circular(20.0),
//                 topRight: new Radius.circular(20.0)), //圆角
//           ),
//           height: 400,
//           child: Obx(() => Container(
//                 width: double.infinity,
//                 height: double.infinity,
//                 // color: Colors.red,
//                 child: Column(children: [
//                   Container(
//                     width: double.infinity,
//                     alignment: Alignment.center,
//                     child: Text(
//                       "支付方式",
//                       style:
//                           TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
//                     ),
//                   ),
//                   Expanded(
//                       child: Container(
//                     width: double.infinity,
//                     height: double.infinity,
//                     // color: Colors.yellow,
//                     child: Column(
//                       children: [
//                         buildRadioGrou(
//                             list: [
//                               {"label": "支付宝支付", "value": "ALI"},
//                               {"label": "积分支付", "value": "JF"},
//                               {"label": "余额支付", "value": "YE"},
//                               {"label": "微信支付", "value": "WX"}
//                             ],
//                             widthFactor: 1,
//                             activeValue: myPayType.value,
//                             onChange: (value) {
//                               myPayType.value = value;
//                               // onChangePayType(value)
//                               // payType.value = value;
//                               // if (onChange !=
//                               //     null) {
//                               //   onChange(value);
//                               // }
//                             }),
//                       ],
//                     ),
//                   )),
//                   Container(
//                     width: double.infinity,
//                     height: 80,
//                     // color: Colors.blue,
//                     padding: EdgeInsets.only(
//                         top: 10, bottom: 10, left: 10, right: 10),
//                     child: buildButton(
//                         title: "确认",
//                         onClick: () {
//                           if (okCallBack != null) {
//                             okCallBack(myPayType.value);
//                           }
//                         },
//                         colors: [Color(0xff0000f4), Color(0xff0000f4)]),
//                   )
//                 ]),
//               ))));
// }
